package com.hniu.mapu.utils;

import lombok.Data;

/**
 * 此类用来封装响应请求
 * @author 惜
 */
@Data
public class RespondUtils {
    private int code;
    private String msg;
    private Object data;

    private RespondUtils(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static RespondUtils success() {
        return new RespondUtils(200, "执行成功", null);
    }

    public static RespondUtils success(Object data) {
        return new RespondUtils(200, "执行成功", data);
    }

    public static RespondUtils success(String msg) {
        return new RespondUtils(200, msg, null);
    }

    public static RespondUtils error() {
        return new RespondUtils(600, "执行错误", null);
    }

    public static RespondUtils error(String msg) {
        return new RespondUtils(600, msg, null);
    }

    public static RespondUtils error(int code, String msg) {
        return new RespondUtils(code, msg, null);
    }

    public static RespondUtils autoCheck(int row) {
        return row > 0 ? success() : error();
    }
}
